package com.karson.zk.nativeapi.utils;

import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class ZooKeeperUtil {

    public static final Integer timeout = 5000;

    public static final String zkServerPath = "zk1:2181,zk2:2181,zk3:2181";

    public static ZooKeeper getInstance() {
        ZooKeeper zookeeper = null;
        try {
            zookeeper = new ZooKeeper(zkServerPath, timeout, event -> {});
        } catch (IOException e) {
            e.printStackTrace();
            if (zookeeper != null) {
                try {
                    zookeeper.close();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        return zookeeper;
    }
}
